package com.hsc.yalebao.tools;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.weight.LogUtils;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class FileTools
{
  public static String SDPATH = "";
  public static BufferedReader bufread;
  private static String readStr = "";

  // ERROR //
  public static String Bitmap2StrByBase64(Bitmap paramBitmap)
  {
    // Byte code:
    //   0: aload_0
    //   1: ifnonnull +6 -> 7
    //   4: ldc 13
    //   6: areturn
    //   7: aconst_null
    //   8: astore_1
    //   9: new 28	java/io/ByteArrayOutputStream
    //   12: dup
    //   13: invokespecial 29	java/io/ByteArrayOutputStream:<init>	()V
    //   16: astore_2
    //   17: aload_0
    //   18: getstatic 35	android/graphics/Bitmap$CompressFormat:JPEG	Landroid/graphics/Bitmap$CompressFormat;
    //   21: bipush 100
    //   23: aload_2
    //   24: invokevirtual 41	android/graphics/Bitmap:compress	(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z
    //   27: pop
    //   28: aload_2
    //   29: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   32: aload_2
    //   33: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   36: aload_2
    //   37: invokevirtual 51	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   40: iconst_0
    //   41: invokestatic 57	android/util/Base64:encodeToString	([BI)Ljava/lang/String;
    //   44: astore 8
    //   46: aload_2
    //   47: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   50: aload_2
    //   51: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   54: aload 8
    //   56: areturn
    //   57: astore 9
    //   59: aload 9
    //   61: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   64: aload 8
    //   66: areturn
    //   67: astore 10
    //   69: aload_1
    //   70: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   73: aload_1
    //   74: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   77: aconst_null
    //   78: areturn
    //   79: astore 4
    //   81: aload 4
    //   83: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   86: goto -9 -> 77
    //   89: astore 5
    //   91: aload_1
    //   92: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   95: aload_1
    //   96: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   99: aload 5
    //   101: athrow
    //   102: astore 6
    //   104: aload 6
    //   106: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   109: goto -10 -> 99
    //   112: astore 5
    //   114: aload_2
    //   115: astore_1
    //   116: goto -25 -> 91
    //   119: astore_3
    //   120: aload_2
    //   121: astore_1
    //   122: goto -53 -> 69
    //
    // Exception table:
    //   from	to	target	type
    //   46	54	57	java/io/IOException
    //   9	17	67	java/lang/Exception
    //   69	77	79	java/io/IOException
    //   9	17	89	finally
    //   91	99	102	java/io/IOException
    //   17	46	112	finally
    //   17	46	119	java/lang/Exception
  }

  public static Bitmap base64ToBitmap(String paramString)
  {
    byte[] arrayOfByte = Base64.decode(paramString, 0);
    return BitmapFactory.decodeByteArray(arrayOfByte, 0, arrayOfByte.length);
  }

  public static void copyDb(String paramString)
  {
    try
    {
      InputStream localInputStream = CustomApplication.app.getAssets().open(paramString);
      File localFile = new File(CustomApplication.app.getFilesDir(), paramString);
      if ((localFile.exists()) && (localFile.length() > 13000L))
      {
        LogUtils.d("....", "addressDbFile.exists");
        return;
      }
      FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
      byte[] arrayOfByte = new byte[1024];
      while (true)
      {
        int i = localInputStream.read(arrayOfByte);
        if (i == -1)
          break;
        localFileOutputStream.write(arrayOfByte, 0, i);
      }
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }

  public static void creatTxtFile(File paramFile)
    throws IOException
  {
    if (!paramFile.exists())
    {
      paramFile.createNewFile();
      System.err.println(paramFile + "已创建！");
    }
  }

  // ERROR //
  public static String imgToBase64FromFile(String paramString)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aload_0
    //   3: ifnull +21 -> 24
    //   6: aload_0
    //   7: invokevirtual 172	java/lang/String:length	()I
    //   10: istore 12
    //   12: aconst_null
    //   13: astore_1
    //   14: iload 12
    //   16: ifle +8 -> 24
    //   19: aload_0
    //   20: invokestatic 175	com/hsc/yalebao/tools/FileTools:readBitmap	(Ljava/lang/String;)Landroid/graphics/Bitmap;
    //   23: astore_1
    //   24: aload_1
    //   25: ifnonnull +6 -> 31
    //   28: ldc 13
    //   30: areturn
    //   31: aconst_null
    //   32: astore_2
    //   33: new 28	java/io/ByteArrayOutputStream
    //   36: dup
    //   37: invokespecial 29	java/io/ByteArrayOutputStream:<init>	()V
    //   40: astore_3
    //   41: aload_1
    //   42: getstatic 35	android/graphics/Bitmap$CompressFormat:JPEG	Landroid/graphics/Bitmap$CompressFormat;
    //   45: bipush 100
    //   47: aload_3
    //   48: invokevirtual 41	android/graphics/Bitmap:compress	(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z
    //   51: pop
    //   52: aload_3
    //   53: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   56: aload_3
    //   57: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   60: aload_3
    //   61: invokevirtual 51	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   64: iconst_0
    //   65: invokestatic 57	android/util/Base64:encodeToString	([BI)Ljava/lang/String;
    //   68: astore 9
    //   70: aload_3
    //   71: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   74: aload_3
    //   75: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   78: aload 9
    //   80: areturn
    //   81: astore 10
    //   83: aload 10
    //   85: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   88: aload 9
    //   90: areturn
    //   91: astore 11
    //   93: aload_2
    //   94: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   97: aload_2
    //   98: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   101: aconst_null
    //   102: areturn
    //   103: astore 5
    //   105: aload 5
    //   107: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   110: goto -9 -> 101
    //   113: astore 6
    //   115: aload_2
    //   116: invokevirtual 44	java/io/ByteArrayOutputStream:flush	()V
    //   119: aload_2
    //   120: invokevirtual 47	java/io/ByteArrayOutputStream:close	()V
    //   123: aload 6
    //   125: athrow
    //   126: astore 7
    //   128: aload 7
    //   130: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   133: goto -10 -> 123
    //   136: astore 6
    //   138: aload_3
    //   139: astore_2
    //   140: goto -25 -> 115
    //   143: astore 4
    //   145: aload_3
    //   146: astore_2
    //   147: goto -54 -> 93
    //
    // Exception table:
    //   from	to	target	type
    //   70	78	81	java/io/IOException
    //   33	41	91	java/lang/Exception
    //   93	101	103	java/io/IOException
    //   33	41	113	finally
    //   115	123	126	java/io/IOException
    //   41	70	136	finally
    //   41	70	143	java/lang/Exception
  }

  public static boolean isExists(File paramFile)
  {
    return paramFile.exists();
  }

  private static Bitmap readBitmap(String paramString)
  {
    try
    {
      Bitmap localBitmap = BitmapFactory.decodeFile(paramString);
      return localBitmap;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public static String readTxtFile(File paramFile)
  {
    try
    {
      bufread = new BufferedReader(new FileReader(paramFile));
      try
      {
        while (true)
        {
          String str = bufread.readLine();
          if (str == null)
          {
            System.out.println("文件内容是:\r\n" + readStr);
            return readStr;
          }
          readStr += str;
        }
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
        localFileNotFoundException.printStackTrace();
    }
  }

  public static String readTxtFile(InputStream paramInputStream)
    throws Exception
  {
    byte[] arrayOfByte = new byte[paramInputStream.available()];
    paramInputStream.read(arrayOfByte);
    paramInputStream.close();
    return new String(arrayOfByte, "UTF-8");
  }

  public static void replaceTxtByStr(File paramFile, String paramString1, String paramString2)
  {
    try
    {
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(paramFile)));
      StringBuffer localStringBuffer1 = new StringBuffer();
      int i = 1;
      String str1 = localBufferedReader.readLine();
      if ((str1 == null) || (str1.equals(paramString1)));
      StringBuffer localStringBuffer2;
      for (Object localObject = localStringBuffer1.append(paramString2); ; localObject = localStringBuffer2)
      {
        String str2 = localBufferedReader.readLine();
        if (str2 == null)
        {
          localBufferedReader.close();
          PrintWriter localPrintWriter = new PrintWriter(new FileOutputStream(paramFile));
          localPrintWriter.write(((StringBuffer)localObject).toString().toCharArray());
          localPrintWriter.flush();
          localPrintWriter.close();
          return;
          localStringBuffer1 = localStringBuffer1.append(str1).append(System.getProperty("line.separator"));
          i++;
          break;
        }
        localStringBuffer2 = ((StringBuffer)localObject).append(System.getProperty("line.separator")).append(str2);
      }
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }

  public static void unZip(Context paramContext, String paramString1, String paramString2)
    throws IOException
  {
    File localFile1 = new File(paramString2);
    if (!localFile1.exists())
      localFile1.mkdirs();
    ZipInputStream localZipInputStream = new ZipInputStream(paramContext.getAssets().open(paramString1));
    ZipEntry localZipEntry = localZipInputStream.getNextEntry();
    byte[] arrayOfByte = new byte[1048576];
    while (true)
    {
      if (localZipEntry == null)
      {
        localZipInputStream.close();
        return;
      }
      if (!localZipEntry.isDirectory())
        break;
      new File(paramString2 + File.separator + localZipEntry.getName()).mkdir();
      localZipEntry = localZipInputStream.getNextEntry();
    }
    File localFile2 = new File(paramString2 + File.separator + localZipEntry.getName());
    localFile2.createNewFile();
    FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
    while (true)
    {
      int i = localZipInputStream.read(arrayOfByte);
      if (i <= 0)
      {
        localFileOutputStream.close();
        break;
      }
      localFileOutputStream.write(arrayOfByte, 0, i);
    }
  }

  public static boolean unZip(String paramString1, String paramString2)
  {
    if (!paramString2.endsWith("/"))
      paramString2 = paramString2 + "/";
    LogUtils.d("unZip()", "目标文件：" + paramString1);
    LogUtils.d("unZip()", "解压地址：" + paramString2);
    byte[] arrayOfByte = new byte[4096];
    try
    {
      localZipInputStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(paramString1)));
      localObject1 = null;
      localObject2 = null;
    }
    catch (IOException localIOException3)
    {
      try
      {
        localZipEntry = localZipInputStream.getNextEntry();
        if (localZipEntry == null)
        {
          LogUtils.d("unZip()", "解压成功！");
          return true;
        }
        localFile1 = new File(paramString2 + localZipEntry.getName());
      }
      catch (IOException localIOException3)
      {
        try
        {
          Object localObject1;
          Object localObject3;
          int i;
          while (true)
          {
            ZipInputStream localZipInputStream;
            ZipEntry localZipEntry;
            File localFile1;
            if (localZipEntry.isDirectory())
            {
              localFile1.mkdirs();
              localObject3 = localObject2;
            }
            try
            {
              while (true)
              {
                localZipInputStream.closeEntry();
                localObject1 = localFile1;
                localObject2 = localObject3;
                break;
                File localFile2 = localFile1.getParentFile();
                if (!localFile2.exists())
                  localFile2.mkdirs();
                localObject3 = new FileOutputStream(localFile1);
                i = localZipInputStream.read(arrayOfByte);
                if (i > 0)
                  break label274;
                ((FileOutputStream)localObject3).close();
              }
            }
            catch (IOException localIOException1)
            {
            }
          }
          while (true)
          {
            label258: localIOException1.printStackTrace();
            LogUtils.e("unZip()", "解压失败！");
            return false;
            label274: ((FileOutputStream)localObject3).write(arrayOfByte, 0, i);
            break;
            localIOException2 = localIOException2;
            continue;
            localIOException3 = localIOException3;
          }
        }
        catch (IOException localIOException4)
        {
          Object localObject2;
          break label258;
        }
      }
    }
  }

  public static void updateFile(String paramString1, String paramString2, String paramString3)
  {
    HttpGet localHttpGet = new HttpGet(paramString1);
    DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
    try
    {
      HttpEntity localHttpEntity = localDefaultHttpClient.execute(localHttpGet).getEntity();
      localHttpEntity.getContentLength();
      InputStream localInputStream = localHttpEntity.getContent();
      if (localInputStream != null)
      {
        File localFile1 = new File(paramString3);
        if (!localFile1.exists())
          localFile1.mkdirs();
        File localFile2 = new File(paramString3, paramString2);
        boolean bool = localFile2.exists();
        FileOutputStream localFileOutputStream = null;
        byte[] arrayOfByte;
        int i;
        if (!bool)
        {
          localFileOutputStream = new FileOutputStream(localFile2);
          arrayOfByte = new byte[1024];
          i = 0;
        }
        while (true)
        {
          int j = localInputStream.read(arrayOfByte);
          if (j == -1)
          {
            localFileOutputStream.flush();
            if (localFileOutputStream == null)
              break;
            localFileOutputStream.close();
            return;
          }
          localFileOutputStream.write(arrayOfByte, 0, j);
          i += j;
        }
      }
    }
    catch (Exception localException)
    {
      LogUtils.e("FileError", localException.toString());
    }
  }

  // ERROR //
  public static void writeTxtFile(File paramFile, String paramString)
    throws IOException
  {
    // Byte code:
    //   0: new 146	java/lang/StringBuilder
    //   3: dup
    //   4: aload_1
    //   5: invokestatic 208	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   8: invokespecial 204	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   11: ldc_w 362
    //   14: invokevirtual 156	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   17: getstatic 15	com/hsc/yalebao/tools/FileTools:readStr	Ljava/lang/String;
    //   20: invokevirtual 156	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   23: ldc_w 362
    //   26: invokevirtual 156	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   29: invokevirtual 160	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   32: astore_2
    //   33: aconst_null
    //   34: astore_3
    //   35: new 364	java/io/RandomAccessFile
    //   38: dup
    //   39: aload_0
    //   40: ldc_w 366
    //   43: invokespecial 367	java/io/RandomAccessFile:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   46: astore 4
    //   48: aload 4
    //   50: aload_2
    //   51: invokevirtual 370	java/io/RandomAccessFile:writeBytes	(Ljava/lang/String;)V
    //   54: aload 4
    //   56: ifnull +63 -> 119
    //   59: aload 4
    //   61: invokevirtual 371	java/io/RandomAccessFile:close	()V
    //   64: return
    //   65: astore 5
    //   67: aload 5
    //   69: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   72: aload_3
    //   73: ifnull -9 -> 64
    //   76: aload_3
    //   77: invokevirtual 371	java/io/RandomAccessFile:close	()V
    //   80: return
    //   81: astore 8
    //   83: aload 8
    //   85: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   88: return
    //   89: astore 6
    //   91: aload_3
    //   92: ifnull +7 -> 99
    //   95: aload_3
    //   96: invokevirtual 371	java/io/RandomAccessFile:close	()V
    //   99: aload 6
    //   101: athrow
    //   102: astore 7
    //   104: aload 7
    //   106: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   109: goto -10 -> 99
    //   112: astore 9
    //   114: aload 9
    //   116: invokevirtual 60	java/io/IOException:printStackTrace	()V
    //   119: return
    //   120: astore 6
    //   122: aload 4
    //   124: astore_3
    //   125: goto -34 -> 91
    //   128: astore 5
    //   130: aload 4
    //   132: astore_3
    //   133: goto -66 -> 67
    //
    // Exception table:
    //   from	to	target	type
    //   35	48	65	java/io/IOException
    //   76	80	81	java/io/IOException
    //   35	48	89	finally
    //   67	72	89	finally
    //   95	99	102	java/io/IOException
    //   59	64	112	java/io/IOException
    //   48	54	120	finally
    //   48	54	128	java/io/IOException
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tools.FileTools
 * JD-Core Version:    0.6.2
 */